<?php

    class biblewidgetmodule {
        function name() { return 'Bible Widget Module'; }
        function description() { return 'Bible widget, on left column'; }
        function author() { return 'Immanuel192'; }

        function hasSources() { return true; }
        function hasContent() { return false; }
        function hasViews() { return true; }

        function supportsWorkflow() { return false; }

        function permissions($internal = '',$type =0) {
            if ($type == 0) {
                $i18n = exponent_lang_loadFile('modules/biblemodule/class.php');
                return array(
                'administrate'=>$i18n['perm_administrate'],
                'manage'=>$i18n['perm_manage_listing'],
                'configure'=>$i18n['perm_configure_listing'],
                'edit'=>$i18n['perm_edit_listing'],
                'delete'=>$i18n['perm_delete_listing'],
                'order'=>$i18n['perm_order_listing'],
                );
            }
            else
            {
                return array("administrate","manage","configure","delete","order");
            }
        }

        function show($view,$loc = null, $title = '') {
            global $db;

            $template = new template('biblewidgetmodule',$view,$loc);

            if ($view == 'Dictionary')
            {
                // For Dictionary
                //$max_id = $db->selectObject("gbible_dic","1 ORDER BY id DESC");
                //$items=intval(substr($max_id->name,1));
                $items=5624;
                
                // we dont have any word with code : 3203 - 3302; so: 3201 -> 3400
                
                $pages=$items/100;
                if ($items % 100 > 0)
                    $pages++;
                // build array for easy smarty template parse
                $data=array();
                for ($i = 0; $i < $pages; $i++){
                    $temp=null;
                    $temp->dfrom=($i)*100+1;
                    $temp->dto=($i+1)*100;
                    if ($temp->dto > $items)
                    {
                        $temp->dto = $items;
                    }
                    // fix bug : code missing :)
                    if ($temp->dfrom == 3201 )
                        $temp->dto=3400;
                    if ($temp->dfrom == 3301)
                        continue;
                    
                    // for sub
                    $temp2=array();
                    for ($k=$temp->dfrom;$k<=$temp->dto;$k++)
                        $temp2[]=$k;
                    $temp->sub_items=$temp2;
                    
                    if ($i< $pages -1 )
                        $data[]=clone $temp;
                }
                $template->assign('dic_array', $data);
            }
            else
            {

                $books=$db->selectObjects("bible_info", "bible_id = 0 ORDER BY bindex");
                // smarty chapter fix
                foreach ($books as $k=>$v){
                    $temp=array();
                    for ($i=0;$i<$v->chapters;$i++)
                    {
                        $temp[$i+1]=$i+1;
                    }
                    $v->chapter_array=$temp;
                }

                $book_id = -1;
                if (isset($_REQUEST['book_id']))
                    $book_id=intval($_REQUEST['book_id']);

                $chapter_id = -1;
                if (isset($_REQUEST['chapter_id']))
                    $chapter_id=intval($_REQUEST['chapter_id']);

                $view_bible_action="";
                if (isset($_REQUEST['action']) && ($_REQUEST['action'] == "view"))
                    $view_bible_action="view";

                $wbible_module="";
                if (isset($_REQUEST['module']) && ($_REQUEST['module'] == "biblemodule"))
                    $wbible_module="biblemodule";

                if (!(($wbible_module == "biblemodule") && ($view_bible_action=="view")))
                {
                    $book_id=-1;
                    $chapter_id=-1;
                }

                $template->assign('books', $books);
                $template->assign('book_id', $book_id);
                $template->assign('chapter_id', $chapter_id);
            }

            $template->assign('moduletitle', $title);
            $template->output();
        }

        function deleteIn($loc) {
            return false;
        }

        function copyContent($oloc,$nloc) {
            global $db;
            return false;
        }

        function searchName() {
            return false;
        }

        function spiderContent($item = null) {
            return false;
        }
    }

?>
